﻿
//初始化
if (typeof ($) != "undefined") {
    var flag = getPar1("flag");
    var TaskTypeID = getPar1("TaskTypeID");
    var TaskTypeName = decodeURI(getPar1("TaskTypeName"));
    $(document).ready(function () {
        //debugger;
        if (flag == "add") {
            $("#TaskTypeID").val(TaskTypeID)
            $("#TaskTypeName").val(TaskTypeName);
            $("#chkDefaulSendEmail").attr("checked", true);
        }
        else {
            //$("#TaskTypeName").val(instance[0].TaskType);
            GetParentType(instance[0].TaskTypeID);

            //发送规则加载
            var SendRule = instance[0].SendRule.split(",");
            for (var i = 0; i < SendRule.length; i++) {
                if (SendRule[i] == "0") $("#chkRule1").attr("checked", 'true');
                if (SendRule[i] == "1") $("#chkRule2").attr("checked", 'true');
            }
            //预警发件人加载
            var IsSetDefaulSendEmail = instance[0].IsSetDefaulSendEmail;
            if (IsSetDefaulSendEmail == "1") {
                $("#chkDefaulSendEmail").attr("checked", true);
            }
            else {
                $("#chkDefaulSendEmail").attr("checked", false);
            }
            //SMTP
            var IsNeedSMTP = instance[0].IsNeedSMTP;
            if (IsNeedSMTP == "1") {
                $("#chkIsNeedSMTP").attr("checked", true);
            }
            else {
                $("#chkIsNeedSMTP").attr("checked", false);
            }

        }
        SetchkDefaulSendEmail();

        if (flag != "add") {
            //加载工作开始结束时间
            var JobStartDate = $("#JobStartDate").val().split(" ");
            $("#JobStartDateDate").val(JobStartDate[0]);
            $("#JobStartDateTime").val(JobStartDate[1]);
            var JobEndDate = $("#JobEndDate").val().split(" ");
            $("#JobEndDateDate").val(JobEndDate[0]);
            $("#JobEndDateTime").val(JobEndDate[1]);
            //加载是否重复执行
            var IsRepeat = instance[0].IsRepeat;
            fnIsRepeat();
            if (IsRepeat == "1") {
                //加载间隔频率
                var JobRepeatIntervalType = instance[0].JobRepeatIntervalType;
                var IntervalWeek = instance[0].IntervalWeek.split(",");
                //alert("JobRepeatIntervalType:" + JobRepeatIntervalType + " IntervalWeek:" + IntervalWeek);
                fnJobRepeatIntervalType();
                for (var i = 0; i < IntervalWeek.length; i++) {
                    if (IntervalWeek[i] == "1") $("#chk1").attr("checked", 'true');
                    if (IntervalWeek[i] == "2") $("#chk2").attr("checked", 'true');
                    if (IntervalWeek[i] == "3") $("#chk3").attr("checked", 'true');
                    if (IntervalWeek[i] == "4") $("#chk4").attr("checked", 'true');
                    if (IntervalWeek[i] == "5") $("#chk5").attr("checked", 'true');
                    if (IntervalWeek[i] == "6") $("#chk6").attr("checked", 'true');
                    if (IntervalWeek[i] == "7") $("#chk7").attr("checked", 'true');
                }
                if (JobRepeatIntervalType == "EveryMonth") {
                    //运行间隔为每月时，加载月执行频率
                    var IntervalMonthType = instance[0].IntervalMonthType;
                    fnIntervalMonthType();
                }

                var EverydayIntervalType = instance[0].EverydayIntervalType;
                fnEverydayIntervalType();
            }
        }
    });

    if (flag == "view") {
        parent.setButtonHiden();
        $("div input").attr("disabled", true).css("background", "whitesmoke");
        $("div textarea ").css("background", "whitesmoke");
        $("div select ").attr("disabled", true).css("background", "whitesmoke");
        $("div input[type=button]").hide();
    }
    $("#taskPlan").css("background", "whitesmoke");
    $("#CronExp").css("background", "whitesmoke");
    $("#TaskTypeName").css("background", "whitesmoke");
}

//获取上级分类信息
function GetParentType(ParentID) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=SysTaskType&condition=ID='" + ParentID + "'";
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        for (var o in list.rows) {
            //debugger;
            var t = list.rows[o].Seq;
            if (typeof (t) != "undefined") {
                $("#TaskTypeName").val(list.rows[o].TaskType);
            }
        }
    });
}

//是否重复执行任务
var fnIsRepeat = function () {
    var IsRepeat = $("#IsRepeat").val();
    //alert("IsRepeat:" + IsRepeat);
    if (IsRepeat == "0") {
        $("#trJobRepeatIntervalType").hide();
        $("#trJobRepeatInterval").hide();
        $("#trIntervalWeek").hide();
        $("#trIntervalMonthType").hide();
        $("#trIntervalMonthDay").hide();
        $("#trIntervalMonthWeek").hide();
        $("#trEverydayIntervalType").hide();
        $("#trEverydayIntervalFrmTime").hide();
        $("#trEverydayIntervalEndTime").hide();
        $("#trEverydayInterval").hide();

    }
    else {
        $("#trJobRepeatIntervalType").show();
        $("#trJobRepeatInterval").show();
        $("#trIntervalWeek").show();
        $("#trIntervalMonthType").show();
        $("#trIntervalMonthDay").show();
        $("#trIntervalMonthWeek").show();
        $("#trEverydayIntervalType").show();
        $("#trEverydayIntervalFrmTime").show();
        $("#trEverydayIntervalEndTime").show();
        $("#trEverydayInterval").show();
        fnJobRepeatIntervalType();
    }

}

//运行间隔类型
var fnJobRepeatIntervalType = function () {
    var JobRepeatIntervalType = $("#JobRepeatIntervalType").val();
    //alert("JobRepeatIntervalType:" + JobRepeatIntervalType);
    if (JobRepeatIntervalType == "EveryDay") {
        $("#trIntervalWeek").hide();
        $("#trIntervalMonthType").hide();
        $("#trIntervalMonthDay").hide();
        $("#trIntervalMonthWeek").hide();

    }
    else if (JobRepeatIntervalType == "EveryWeek") {
        $("#trIntervalWeek").show();
        $("#trIntervalMonthType").hide();
        $("#trIntervalMonthDay").hide();
        $("#trIntervalMonthWeek").hide();
    }
    else if (JobRepeatIntervalType == "EveryMonth") {
        $("#trIntervalWeek").hide();
        $("#trIntervalMonthType").show();
        $("#trIntervalMonthDay").show();
        $("#trIntervalMonthWeek").hide();
        fnIntervalMonthType();
    } else {
        $("#trIntervalWeek").show();
        $("#trIntervalMonthType").show();
        $("#trIntervalMonthDay").show();
        $("#trIntervalMonthWeek").show();
    }
}

//每月执行频率类型
var fnIntervalMonthType = function () {
    var IntervalMonthType = $("#IntervalMonthType").val();
    //alert("IntervalMonthType:" + IntervalMonthType);
    if (IntervalMonthType == "1") {
        $("#trIntervalMonthDay").show();
        $("#trIntervalMonthWeek").hide();
    }
    else {
        $("#trIntervalMonthDay").hide();
        $("#trIntervalMonthWeek").show();
    }
}

//每天重复执行
var fnEverydayIntervalType = function () {
    var EverydayIntervalType = $("#EverydayIntervalType").val();
    //alert("EverydayIntervalType:" + EverydayIntervalType);
    if (EverydayIntervalType == "1") {
        $("#trEverydayInterval").show();
    }
    else {
        $("#trEverydayInterval").hide();
    }
}

//设置工作开始时间
var SetJobStartDate = function () {
    var tempTime = $("#JobStartDateTime").val() + ":01";
    if ($("#JobStartDateTime").val() != "") {
        if (!isTime(tempTime)) {
            alert("工作开始时间格式不对!");
            return;
        }
    }
    $("#JobStartDate").val($("#JobStartDateDate").val() + " " + $("#JobStartDateTime").val());
}

//设置工作结束时间
var SetJobEndDate = function () {
    var tempTime = $("#JobEndDateTime").val() + ":01";
    if ($("#JobEndDateTime").val() != "") {
        if (!isTime(tempTime)) {
            alert("工作结束时间格式不对!");
            return;
        }
    }
    $("#JobEndDate").val($("#JobEndDateDate").val() + " " + $("#JobEndDateTime").val());
}

//设置周频率
var SetIntervalWeek = function () {
    var str = "";
    $("input:checkbox[name='checkbox']:checked").each(function () {
        str += $(this).val() + ",";
    });
    if (str != "") str = str.substr(0, str.length - 1);
    //alert(str);
    $("#IntervalWeek").val(str);
}


//生成任务计划
function CreateTaskPlan() {
    //alert("**");
    //debugger;
    var msg = fnCheckData();
    if (typeof (msg) != "undefined" && msg != "") {
        alert(msg);
        return;
    }
    var taskPlan = "任务";
    var cronExp = "";
    var JobRepeatIntervalType = $("#JobRepeatIntervalType").val();
    var JobRepeatInterval = $("#JobRepeatInterval").val();
    var EverydayIntervalType = $("#EverydayIntervalType").val();
    var EverydayIntervalFrmTime = $("#EverydayIntervalFrmTime").val();
    var EverydayIntervalEndTime = $("#EverydayIntervalEndTime").val();
    var EverydayInterval = $("#EverydayInterval").val();
    var EverydayIntervalUnit = $("#EverydayIntervalUnit").val();
    var strEverydayIntervalUnit = "";
    switch (EverydayIntervalUnit) {
        case "H":
            strEverydayIntervalUnit = "小时";
            break;
        case "M":
            strEverydayIntervalUnit = "分";
            break;
        case "S":
            strEverydayIntervalUnit = "秒";
            break;
    }

    //周频率
    var IntervalWeek = $("#IntervalWeek").val().split(",");
    var strIntervalWeek = "";
    for (var i = 0; i < IntervalWeek.length; i++) {
        if (IntervalWeek[i] == "1") strIntervalWeek += "星期日,";
        if (IntervalWeek[i] == "2") strIntervalWeek += "星期一,";
        if (IntervalWeek[i] == "3") strIntervalWeek += "星期二,";
        if (IntervalWeek[i] == "4") strIntervalWeek += "星期三,";
        if (IntervalWeek[i] == "5") strIntervalWeek += "星期四,";
        if (IntervalWeek[i] == "6") strIntervalWeek += "星期五,";
        if (IntervalWeek[i] == "7") strIntervalWeek += "星期六,";
    }

    //月频率
    var IntervalMonthType = $("#IntervalMonthType").val();
    var IntervalMonthDay = $("#IntervalMonthDay").val();
    var NumWeekDay = $("#NumWeekDay").val();
    var strNumWeekDay = "";
    var IntervalMonthWeek = $("#IntervalMonthWeek").val();
    var strIntervalMonthWeek = "";
    switch (NumWeekDay) {
        case "1":
        case "2":
        case "3":
        case "4":
            strNumWeekDay = "第" + NumWeekDay + "个";
            break;
        case "5":
            strNumWeekDay = "最后一个";
            break;
    }
    switch (IntervalMonthWeek) {
        case "1":
            strIntervalMonthWeek = "周一";
            break;
        case "2":
            strIntervalMonthWeek = "周二";
            break;
        case "3":
            strIntervalMonthWeek = "周三";
            break;
        case "4":
            strIntervalMonthWeek = "周四";
            break;
        case "5":
            strIntervalMonthWeek = "周五";
            break;
        case "6":
            strIntervalMonthWeek = "周六";
            break;
        case "7":
            strIntervalMonthWeek = "周日";
            break;
        case "8":
            strIntervalMonthWeek = "工作日";
            break;
        case "9":
            strIntervalMonthWeek = "休息日";
            break;
    }

    //开始组装计划
    taskPlan += $("#TaskName").val() + "";
    taskPlan += "在" + $("#JobStartDate").val() + "";
    taskPlan += "和" + $("#JobEndDate").val() + "之间使用计划.";

    //格式化字符串
    var JobStartDateDate = $("#JobStartDateDate").val().split("-");
    var JobStartDateTime = $("#JobStartDateTime").val().split(":");
    var arrEverydayIntervalFrmTime = EverydayIntervalFrmTime.split(":");
    var arrEverydayIntervalEndTime = EverydayIntervalEndTime.split(":");

    if ($("#IsRepeat").val() == "1") {
        if (JobRepeatIntervalType == "EveryDay") {
            if (EverydayIntervalType == "1") {
                //每3天在07:04和19:10之间、每隔3分执行.
                taskPlan += "每" + JobRepeatInterval + "天在" + EverydayIntervalFrmTime + "和" + EverydayIntervalEndTime + "之间、每隔" +
                                EverydayInterval + strEverydayIntervalUnit + "执行.";
                switch (EverydayIntervalUnit) {
                    case "H":
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + "/" + EverydayInterval + " "
                        + "1/" + JobRepeatInterval + " " + "*" + " " + "?" + " " + "*";
                        break;
                    case "M":
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + "/" + EverydayInterval + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + "1/" + JobRepeatInterval + " " + "*" + " " + "?" + " " + "*";
                        break;
                    case "S":
                        cronExp = "0" + "/" + EverydayInterval + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + "1/" + JobRepeatInterval + " " + "*" + " " + "?" + " " + "*";
                        break;
                }
            }
            else {
                //每3天在07:04执行.
                taskPlan += "每" + JobRepeatInterval + "天在" + EverydayIntervalFrmTime + "执行.";
                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + " " + arrEverydayIntervalFrmTime[0] * 1 + " "
                    + "1/" + JobRepeatInterval + " " + "*" + " " + "?" + " " + "*";
            }
        }
        else if (JobRepeatIntervalType == "EveryWeek") {
            if (EverydayIntervalType == "1") {
                //每3周的星期一,星期三,星期六,星期日,在07:04和19:10之间、每隔3分执行.
                taskPlan += "每" + JobRepeatInterval + "周的" + strIntervalWeek + "在" + EverydayIntervalFrmTime + "和" + EverydayIntervalEndTime + "之间、每隔" +
                                EverydayInterval + strEverydayIntervalUnit + "执行.";
                switch (EverydayIntervalUnit) {
                    case "H":
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + "/" + EverydayInterval + " "
                        + "?" + " " + "*" + " " + IntervalWeek + "/" + JobRepeatInterval + " " + "*";
                        break;
                    case "M":
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + "/" + EverydayInterval + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + "?" + " " + "*" + " " + IntervalWeek + "/" + JobRepeatInterval + " " + "*";
                        break;
                    case "S":
                        cronExp = "0" + "/" + EverydayInterval + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + "?" + " " + "*" + " " + IntervalWeek + "/" + JobRepeatInterval + " " + "*";
                        break;
                }
            }
            else {
                //每3周的星期一,星期三,星期四,在07:04执行.
                taskPlan += "每" + JobRepeatInterval + "周的" + strIntervalWeek + "在" + EverydayIntervalFrmTime + "执行.";
                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + " " + arrEverydayIntervalFrmTime[0] * 1 + " "
                    + "?" + " " + "*" + " " + IntervalWeek + "/" + JobRepeatInterval + " " + "*";
            }
        }
        else if (JobRepeatIntervalType == "EveryMonth") {
            if (IntervalMonthType == "1") {
                if (EverydayIntervalType == "1") {
                    //每3个月,于当月第3天,在07:04和19:10之间、每隔3分执行.
                    taskPlan += "每" + JobRepeatInterval + "个月,于当月第" + IntervalMonthDay + "天,在" + EverydayIntervalFrmTime + "和" + EverydayIntervalEndTime + "之间、每隔" +
                                EverydayInterval + strEverydayIntervalUnit + "执行.";
                    switch (EverydayIntervalUnit) {
                        case "H":
                            cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + "/" + EverydayInterval + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + "?" + " " + "*";
                            break;
                        case "M":
                            cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + "/" + EverydayInterval + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + "?" + " " + "*";
                            break;
                        case "S":
                            cronExp = "0" + "/" + EverydayInterval + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + "?" + " " + "*";
                            break;
                    }
                }
                else {
                    //每3个月,于当月第3天,在07:04执行.
                    taskPlan += "每" + JobRepeatInterval + "个月,于当月第" + IntervalMonthDay + "天,在" + EverydayIntervalFrmTime + "执行.";
                    cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + " " + arrEverydayIntervalFrmTime[0] * 1 + " "
                    + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + "?" + " " + "*";
                }
            }
            else {
                if (EverydayIntervalType == "1") {
                    //每3个月的第1个周三,在07:04和19:10之间、每隔3分执行.
                    taskPlan += "每" + JobRepeatInterval + "个月的" + strNumWeekDay + strIntervalMonthWeek + ",在" + EverydayIntervalFrmTime + "和" + EverydayIntervalEndTime + "之间、每隔" +
                                EverydayInterval + strEverydayIntervalUnit + "执行.";
                    if (NumWeekDay < 5) {
                        //每月的第几个周几
                        switch (EverydayIntervalUnit) {
                            case "H":
                                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + "/" + EverydayInterval + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "#" + NumWeekDay + " " + "*";
                                break;
                            case "M":
                                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + "/" + EverydayInterval + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "#" + NumWeekDay + " " + "*";
                                break;
                            case "S":
                                cronExp = "0" + "/" + EverydayInterval + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "#" + NumWeekDay + " " + "*";
                                break;
                        }
                    }
                    else {
                        //每月的最后周几
                        switch (EverydayIntervalUnit) {
                            case "H":
                                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + "/" + EverydayInterval + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "L" + " " + "*";
                                break;
                            case "M":
                                cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + "/" + EverydayInterval + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "L" + " " + "*";
                                break;
                            case "S":
                                cronExp = "0" + "/" + EverydayInterval + " " + arrEverydayIntervalFrmTime[1] * 1 + "-" + arrEverydayIntervalEndTime[1] * 1 + " "
                        + arrEverydayIntervalFrmTime[0] * 1 + "-" + arrEverydayIntervalEndTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "L" + " " + "*";
                                break;
                        }
                    }
                }
                else {
                    //每3个月的第2个周三,在07:04执行.
                    taskPlan += "每" + JobRepeatInterval + "个月的" + strNumWeekDay + strIntervalMonthWeek + ",在" + EverydayIntervalFrmTime + "执行.";
                    if (NumWeekDay < 5) {
                        //每月的第几个周几
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + " " + arrEverydayIntervalFrmTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "#" + NumWeekDay + " " + "*";
                    }
                    else {
                        //每月的最后周几
                        cronExp = "0" + " " + arrEverydayIntervalFrmTime[1] * 1 + " " + arrEverydayIntervalFrmTime[0] * 1 + " "
                        + IntervalMonthDay + " " + "1/" + JobRepeatInterval + " " + IntervalMonthWeek + "L" + " " + "*";
                    }
                }
            }
        }
        taskPlan += "";
    }
    else {
        taskPlan = "任务" + $("#TaskName").val() + "在" + $("#JobStartDate").val() + " 运行一次";
        cronExp = "0" + " " + JobStartDateTime[1] * 1 + " " + JobStartDateTime[0] * 1 + " "
                    + JobStartDateDate[2] * 1 + " " + JobStartDateDate[1] * 1 + " " + "?" + " " + JobStartDateDate[0] * 1;
    }
    $("#taskPlan").val(taskPlan);
    $("#CronExp").val(cronExp);
}

//预警条件
var taskMsgCondition = $("#MsgCondition").val();
var SetCondition = function () {
    //debugger;
    //alert("预警条件");
    document.getElementById("EditUIWindow").src = "../EHR/taskMsgCondition.aspx?flag=1&r=" + Math.random() + "&datatableName=" + $("#TaskName").val();
    setTimeout(function () {
        $("#dialogArea").fbmodal({
            title: "预警条件设置",
            cancel: "退出",
            okay: "确定",
            modal: true,
            okaybutton: true,
            cancelbutton: true,
            buttons: true,
            opacity: 0.0,
            fadeout: true,
            overlayclose: true,
            modaltop: "80%",
            modalwidth: "450",
            modalheight: "270"
        }, _callBackMsgCondition);
    }, 100);
}

//预警内容
var taskMsgCNContent = $("#MsgCNContent").val();
var taskMsgENContent = $("#MsgENContent").val();
var SetMsgContent = function () {
    //alert("预警内容");
    document.getElementById("EditUIWindow").src = "../EHR/taskMsgContent.aspx?flag=1&r=" + Math.random() + "&datatableName=" + $("#TaskName").val();
    setTimeout(function () {
        $("#dialogArea").fbmodal({
            title: "预警内容设置",
            cancel: "退出",
            okay: "确定",
            modal: true,
            okaybutton: true,
            cancelbutton: true,
            buttons: true,
            opacity: 0.0,
            fadeout: true,
            overlayclose: true,
            modaltop: "80%",
            modalwidth: "450",
            modalheight: "270"
        }, _callBackMsgContent);
    }, 100);
}

//发送规则
var SetSendRule = function () {
    //alert("发送规则");
    var str = "";
    $("input:checkbox[name='chkSendRule']:checked").each(function () {
        str += $(this).val() + ",";
    });
    if (str != "") str = str.substr(0, str.length - 1);
    //alert(str);
    $("#SendRule").val(str);

}

//设置接收对象
var taskMsgReceiveObject = $("#ReceiveObject").val();
var SetReceiveObject = function () {
    //alert("设置接收对象");
    document.getElementById("EditUIWindow").src = "../EHR/taskMsgReceiveObject.aspx?flag=1&r=" + Math.random() + "&datatableName=" + $("#TaskName").val();
    setTimeout(function () {
        $("#dialogArea").fbmodal({
            title: "预警内容设置",
            cancel: "退出",
            okay: "确定",
            modal: true,
            okaybutton: true,
            cancelbutton: true,
            buttons: true,
            opacity: 0.0,
            fadeout: true,
            overlayclose: true,
            modaltop: "120%",
            modalwidth: "800",
            modalheight: "270"
        }, _callBackMsgReceiveObject);
    }, 100);
}

//用于预警条件对话框"确定"按钮的回调
var _callBackMsgCondition = function (status) {
    if (status == 1) {
        $("#MsgCondition").val(taskMsgCondition);
    }
}

//用于预警内容对话框"确定"按钮的回调
var _callBackMsgContent = function (status) {
    if (status == 1) {
        $("#MsgCNContent").val(taskMsgCNContent);
        $("#MsgENContent").val(taskMsgENContent);
    }
}

//用于接收对象对话框"确定"按钮的回调
var _callBackMsgReceiveObject = function (status) {
    if (status == 1) {
        $("#ReceiveObject").val(taskMsgReceiveObject);
    }
}

//预警发件人信息
var SetchkDefaulSendEmail = function () {
    //alert($("#chkDefaulSendEmail").attr("checked"));
    //alert(document.getElementsByName("chkDefaulSendEmail")[0].checked);
    //debugger;
    //if (!$("#chkDefaulSendEmail").attr("checked")) {
    if (!document.getElementsByName("chkDefaulSendEmail")[0].checked) {
        $("#IsSetDefaulSendEmail").val("0")
        $("#SendEmail").attr("readonly", "readonly").css("background", "whitesmoke").val("");
        $("#SendEmailName").attr("readonly", "readonly").css("background", "whitesmoke").val("");
        $("#chkIsNeedSMTP").attr("disabled", "true").css("background", "whitesmoke").attr("checked", false);

    }
    else {
        $("#IsSetDefaulSendEmail").val("1")
        $("#SendEmail").removeAttr("readonly").css("background", "white");
        $("#SendEmailName").removeAttr("readonly").css("background", "white");
        $("#chkIsNeedSMTP").removeAttr("disabled").css("background", "white");
    }
    SetIsNeedSMTP();
}

//SMTP服务需要认证
var SetIsNeedSMTP = function () {
    //if (!$("#chkIsNeedSMTP").attr("checked")) {
    if (!document.getElementsByName("chkIsNeedSMTP")[0].checked) {
        $("#IsNeedSMTP").val("0")
        $("#SMTPEmailName").attr("readonly", "readonly").css("background", "whitesmoke").val("");
        $("#SMTPEmailPWD").attr("readonly", "readonly").css("background", "whitesmoke").val("");
    }
    else {
        $("#IsNeedSMTP").val("1")
        $("#SMTPEmailName").removeAttr("readonly").css("background", "white");
        $("#SMTPEmailPWD").removeAttr("readonly").css("background", "white");
    }
}

var fnCheckData = function () {
    try {
        if ($("#TaskName").val() == "") {
            return "任务名不能为空！";
        }

        var tempTime = $("#JobStartDateTime").val() + ":01";
        if ($("#JobStartDateTime").val() != "") {
            if (!isTime(tempTime)) {
                return "工作开始时间格式不对!";
            }
        }

        tempTime = $("#JobEndDateTime").val() + ":01";
        if ($("#JobStartDateTime").val() != "") {
            if (!isTime(tempTime)) {
                return "工作结束时间格式不对!";
            }
        }
        var reg = /^\d+(\.\d+)?$/;
        if ($("#JobRepeatInterval").val() != "") {
            if (reg.test($("#JobRepeatInterval").val()) == false) {
                return "运行间隔需要输入非零数字!";
            }
        }
    }
    catch (e)
     { }

}












